<template>
  <div id="app">
    <div class="container">
      <div class="form-warp">
        <form class="sign-in-form">
          <h2 class="form-title">登录</h2>
          <input placeholder="用户名" v-model="userlogin.urName" />
          <input
            type="password"
            placeholder="密码"
            v-model="userlogin.urPassword"
          />
          <input
            placeholder="验证码"
            id="username"
            v-model="userlogin.urCaptcha"
          />
          <img :src="sn" alt="" class="yzm" @click="start" />
          <div class="submit-btn" @click="login()">立即登录</div>
        </form>
        <form class="sign-up-form">
          <h2 class="form-title">注册</h2>
          <input placeholder="用户名" id="username" v-model="user.urName" />
          <input
            type="password"
            placeholder="密码"
            id="userpassword"
            v-model="user.urPassword"
          />
          <van-radio-group v-model="user.urSex" direction="horizontal">
            <van-radio name="男">男</van-radio>
            <van-radio name="女">女</van-radio>
          </van-radio-group>
          <input placeholder="QQ号" id="username" v-model="user.urQq" />
          <input placeholder="手机号" id="username" v-model="user.urPhone" />
          <input placeholder="验证码" id="username" v-model="user.urCaptcha" />
          <img :src="sn" alt="" class="yzm" @click="start" />
          <div class="submit-btn" id="zhuche" @click="zhuche()">立即注册</div>
        </form>
      </div>
      <div class="desc-warp">
        <div class="desc-warp-item sign-up-desc">
          <div class="content">
            <button id="sign-up-btn">注册</button>
          </div>
         <!--   <img src="/static/img/log.svg" alt="" />-->
        </div>
        <div class="desc-warp-item sign-in-desc">
          <div class="content">
            <button id="sign-in-btn">登录</button>
          </div>
          <!-- <img src="@/img/register.svg" alt="" /> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import {swiper} from '@/assets/js/main.js'
// import {hhh} from '@/assets/js/jquery.min.js'
// import {aa} from '@/assets/js/main.js'
var dataformat = {
  urName: "",
  urPassword: "",
  urSex: "",
  urQq: "",
  urPhone: "",
  urCaptcha: "",
  encrypts:""
};
import api from "@/api/index";
export default {
  mounted() {
    const singUpBtn = document.querySelector("#sign-up-btn");
    const singInBtn = document.querySelector("#sign-in-btn");
    const container = document.querySelector(".container");

    singUpBtn.addEventListener("click", () => {
      container.classList.add("sign-up-mode");
    });
    singInBtn.addEventListener("click", () => {
      container.classList.remove("sign-up-mode");
    });
    this.start();
  },
  data() {
    return {
      sn: "hhh",
      user: dataformat,
      userlogin: {
        urName: "",
        urPassword: "",
        urCaptcha: "",
        encrypts:"",
      },
    };
  },
  methods: {
    //登录提交
    login() {
      var _this = this
      api.login(this.userlogin).then((res) => {
        this.start();
        this.$dialog({
          message: res.data.message,
        }); 
        // 存储
        localStorage.setItem("tokenlo",res.data.data.user.urId)
        _this.$router.push('/PD');
        // // 取用
      });
    },
    //注册提交
    zhuche() {
      // if(this.user.urPhone)
      
      api.zc(this.user).then((res) => {
        this.start();
        this.$dialog({
          message: res.data.message,
        });
      });
      this.user = dataformat;
    },
    //获取验证码
    start() {
      var _this = this;
      api.captcha().then((result) => {
        _this.sn = result.data.data.captcha;
        _this.userlogin.encrypts = result.data.data.encrypts
        _this.user.encrypts = result.data.data.encrypts
      });
    },
  },
};
</script>
<style scoped>
/*
 * Author: Minyoung
 * CreateAt: 2021年10月14日23:44:45
 * License: MIT
 */
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  color: #333;
}
.yzm{
  width: 100px;
  height: 50px;
}

input {
  margin: 5px 0;
}

.container {
  position: relative;
  min-height: 100vh;
  width: 100%;
  overflow: hidden;
}
.container::before {
  content: " ";
  position: absolute;
  width: 2000px;
  height: 2000px;
  margin-bottom: 0%;
  border-radius: 50%;
  background-image: linear-gradient(-45deg, #6266f5 0%, #04befe 100%);
  transition: 1.8s ease-in-out;
  z-index: 6;
  top: -10%;
  right: 48%;
  transform: translateY(-50%);
}
.container.sign-up-mode::before {
  transform: translate(100%, -50%);
}

.form-warp {
  width: 50%;
  position: absolute;
  z-index: 5;
  left: 75%;
  top: 50%;
  z-index: 5;
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: 1fr;
  transition: 1s 0.7s ease-in-out; 
}
.form-warp form {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  /* 将两个 form 布局在 grid 同一位置 */
  grid-row: 1 / 2;
  grid-column: 1 / 2;
  transition: all 0.2s 0.7s;
  opacity: 1;
  z-index: 4;
}
.form-title {
  color: #6266f5;
}
.sign-up-form{
  margin-top: -130px;
}
.form-warp .sign-up-form {
  opacity: 0;
  z-index: 3;
}
.container.sign-up-mode .form-warp {
  left: 25%;
}
.container.sign-up-mode .sign-in-form {
  opacity: 0;
  z-index: 3;
}
.container.sign-up-mode .sign-up-form {
  opacity: 1;
  z-index: 4;
}
#zhuche {
  position: relative;
  z-index: 99;
}
input,
.submit-btn {
  min-width: 300px;
  outline: none;
  padding: 12px 30px;
  line-height: 1;
  font-size: 16px;
  border-radius: 60px;
  color: #333;
  background-color: #6267f513;
  border: none;
}
input::placeholder {
  color: #cccc;
}
.submit-btn {
  background-color: #6266f5;
  color: #FFF;
  text-align: center;
  min-width: 150px;
  font-size: initial;
  font-weight: bold;
  letter-spacing: 1.5px;
  cursor: pointer;
}

.desc-warp {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}
.desc-warp-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-around;
  text-align: center;
  text-align: center;
  padding: 3rem 17% 2rem 12%;
  z-index: 6;
}
/* 事件穿透 BEGIN */
.sign-in-desc {
  pointer-events: none;
}
.sign-up-mode .sign-in-desc {
  pointer-events: all;
}
.sign-up-mode .sign-up-desc {
  pointer-events: none;
}
/* 事件穿透 END */
.content {
  width: 100%;
  transition: transform 0.9s ease-in-out;
  transition-delay: .6s;
}
.sign-in-desc img,
.sign-in-desc .content {
  transform: translateX(800px);
}
.sign-up-mode .sign-in-desc img,
.sign-up-mode .sign-in-desc .content {
  transform: translateX(0);
}

.sign-up-mode .sign-up-desc img,
.sign-up-mode .sign-up-desc .content {
  transform: translateX(-800px);
}

button {
  outline: none;
  padding: 6px 8px;
  min-width: 100px;
  text-align: center;
  border-radius: 30px;
  border: 2px solid #6266f5;
  background:#6266f5;
  color: rgb(255, 255, 255);
  cursor: pointer;
  transition: all .3s ease;
}
button:active {
  background: rgba(255, 255, 255, .1);
}
img {
  width: 100%;
  display: block;
  transition: transform 0.9s ease-in-out;
  transition-delay: .5s;
}

/* 响应式 */
@media screen and (max-width: 870px) {
  .container::before {
    width: 0;
    height: 1500px;
    transform: translateX(-50%);
    left: 30%;
    bottom: 68%;
    right: initial;
    top: initial;
    transition: 2s ease-in-out;
  }
  .container.sign-up-mode::before {
    transform: translate(-50%, 100%);
    bottom: 32%;
    right: initial;
  }
  .form-warp {
    width: 100%;
    top: 80%;
    left: 50%;
    transform: translate(-50%, -100%);
    transition: 1s 0.8s ease-in-out;
  }
  .container.sign-up-mode .form-warp {
    top: 25%;
    left: 50%;
    transform: translate(-50%, 0);
  }
  img {
    width: 200px;
    transition: transform 0.9s ease-in-out;
    transition-delay: 0.7s;
  }
  .desc-warp {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 2fr 1fr;
  }
  .desc-warp-item {
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: 2.5rem 8%;
    grid-column: 1 / 2;
  }
  .sign-in-desc {
    grid-row: 3 / 4;
  }

  .sign-in-desc img,
  .sign-in-desc .content {
    transform: translateY(800px);
  }

  .sign-up-mode .sign-in-desc img,
  .sign-up-mode .sign-in-desc .content {
    transform: translateY(0);
  }

  .sign-up-mode .sign-up-desc img,
  .sign-up-mode .sign-up-desc .content {
    transform: translateY(-800px);
  }
}

@media screen and (max-width: 570px) {
  .container::before {
    bottom: 95%;
    left: 50%;
  }
  img {
    /* display: none; */
  }
}
</style>